<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Profit;
use App\Models\OrderGoods;

class ProfitController extends BaseController
{
    
    /**
     * 利润列表
     * @return [type] [description]
     */
    public function profitList(Request $request) {
    
        $id        =  $this->shop_id;

        $type      =  $request->input('type',1);

        $beginTime = $request->input('beginTime');//开始时间

        $endTime   = $request->input('endTime');//结束时间

        $profit    = new profit();

        $beginTime != null && $profit = $profit->where('created_at', '>=', $beginTime);

        $endTime   != null && $profit = $profit->where('created_at', '<=', $endTime);

        $data =  $profit->where('shop_id', $id)
                        ->where('type', $type)
                        ->orderBy('created_at', 'desc')
                        ->paginate($this->pageSize)
                        ->toArray();

        //查询出订单列表中的产品
        $data['data'] = OrderGoods::getOrderList($data['data']);

        return self::json($data);
    }

    /**
     * 交易流水列表
     * @return [type] [description]
     */
    public function waterList(Request $request) {
    
        $id        =  $this->shop_id;

        $type      =  $request->input('type');

        $beginTime = $request->input('beginTime');//开始时间

        $endTime   = $request->input('endTime');//结束时间

        $profit = new profit();

        $beginTime != null && $profit = $profit->where('created_at', '>=', $beginTime);

        $endTime   != null && $profit = $profit->where('created_at', '<=', $beginTime);

        $data = $profit->where('shopid', $id)
                        ->where('type', $type)
                        ->orderBy('created_at', 'desc')
                        ->paginate($this->pageSize);

        return self::json($data);
    }

}
